/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.escom.healthlc.ws;

import com.escom.healthlc.entidad.ArritmiaVO;
import com.escom.healthlc.entidad.ConsultaVO;
import com.escom.healthlc.entidad.EnfermedadVO;
import com.escom.healthlc.entidad.HistoriaFamiliarVO;
import com.escom.healthlc.entidad.HospitalVO;
import com.escom.healthlc.entidad.MedicoVO;
import com.escom.healthlc.entidad.MngSyncVO;
import com.escom.healthlc.entidad.PacienteVO;
import com.escom.healthlc.entidad.ParentescoVO;
import com.escom.healthlc.imapperdao.IArritmiaMapper;
import com.escom.healthlc.imapperdao.IConsultaMapper;
import com.escom.healthlc.imapperdao.IEnfermedadMapper;
import com.escom.healthlc.imapperdao.IHistoriaFamiliarMapper;
import com.escom.healthlc.imapperdao.IHospitalMapper;
import com.escom.healthlc.imapperdao.IPacienteMapper;
import com.escom.healthlc.imapperdao.IParentescoMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Carlos
 */
@Controller
@RequestMapping("/mngPacienteWebService")
public class MngPacienteWebService {

    @Autowired
    private IHistoriaFamiliarMapper historiaFamiliarMapper;
    @Autowired
    private IPacienteMapper pacienteMapper;
    @Autowired
    private IEnfermedadMapper enfermedadMapper;
    @Autowired
    private IParentescoMapper parentescoMapper;
    @Autowired
    private IHospitalMapper hospitalMapper;
    @Autowired
    private IArritmiaMapper arritmiaMapper;
    @Autowired
    private IConsultaMapper consultaMapper;

    private MedicoVO medico;

    @RequestMapping(method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public @ResponseBody
    MngSyncVO getMngPacientesJSON(@RequestParam(value = "idMedico") String idMedico) {
        medico = new MedicoVO();
        medico.setIdMedico(idMedico);
        MngSyncVO mngSyncVO = new MngSyncVO();

        List<HistoriaFamiliarVO> historiaFamiliar = historiaFamiliarMapper.retrieveHistoriaFamiliar(idMedico, null);
        HistoriaFamiliarVO[] arrayHistoriaFamiliar = new HistoriaFamiliarVO[historiaFamiliar.size()];
        for (int i = 0; i < historiaFamiliar.size(); i++) {
            arrayHistoriaFamiliar[i] = historiaFamiliar.get(i);
        }

        List<ParentescoVO> parentesco = parentescoMapper.retrieveListParentesco();
        ParentescoVO[] arrayParentesco = new ParentescoVO[parentesco.size()];
        for (int i = 0; i < parentesco.size(); i++) {
            arrayParentesco[i] = parentesco.get(i);
        }

        List<EnfermedadVO> enfermedad = enfermedadMapper.retrieveListEnfermedad();
        EnfermedadVO[] arrayEnfermedad = new EnfermedadVO[enfermedad.size()];
        for (int i = 0; i < enfermedad.size(); i++) {
            arrayEnfermedad[i] = enfermedad.get(i);
        }

        List<PacienteVO> pacientesByMedico = pacienteMapper.retrievePacientesByMedico(medico);
        PacienteVO[] arrayPacientes = new PacienteVO[pacientesByMedico.size()];
        for (int i = 0; i < pacientesByMedico.size(); i++) {
            arrayPacientes[i] = pacientesByMedico.get(i);
        }

        List<HospitalVO> retrieveListHospital = hospitalMapper.retrieveListHospital();
        HospitalVO[] arrayHospitales = new HospitalVO[retrieveListHospital.size()];
        for (int i = 0; i < retrieveListHospital.size(); i++) {
            arrayHospitales[i] = retrieveListHospital.get(i);
        }

        List<ArritmiaVO> arritmias = arritmiaMapper.retrieveListArritmia();
        ArritmiaVO[] arrayArritmias = new ArritmiaVO[arritmias.size()];
        for (int i = 0; i < arritmias.size(); i++) {
            arrayArritmias[i] = arritmias.get(i);
        }
        
        List<ConsultaVO> retrieveConsultas = consultaMapper.retrieveConsultas(idMedico, null);
        ConsultaVO[] arrayConsultas = new ConsultaVO[retrieveConsultas.size()];
        for (int i = 0; i < retrieveConsultas.size(); i++) {
            arrayConsultas[i] = retrieveConsultas.get(i);
        }

        mngSyncVO.setConsultas(arrayConsultas);
        mngSyncVO.setEnfermedad(arrayEnfermedad);
        mngSyncVO.setHistoriaFamiliar(arrayHistoriaFamiliar);
        mngSyncVO.setPacientes(arrayPacientes);
        mngSyncVO.setParentesco(arrayParentesco);
        mngSyncVO.setHospital(arrayHospitales);
        mngSyncVO.setArritmia(arrayArritmias);
        return mngSyncVO;
    }

}
